Skip to content

chore: added console.errro - #30

Merged
yash-pouranik merged 1 commit into
mainfrom
feat/ui-updates
Mar 2, 2026
Merged

chore: added console.errro#30
yash-pouranik merged 1 commit into
mainfrom
feat/ui-updates

Conversation

@yash-pouranik

@yash-pouranik yash-pouranik commented Mar 2, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved error handling with better error logging in data and schema operations for easier troubleshooting.
    • Added validation to return appropriate error when attempting to create a schema for a non-existent project.

@vercel

vercel Bot commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ur-backend Ready Ready Preview, Comment Mar 2, 2026 4:54pm

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the backend's error handling and code readability. It introduces explicit console.error logging within catch blocks across various data and schema management functions, ensuring that errors are more visibly reported. Additionally, it cleans up the codebase by removing several redundant or explanatory comments, leading to a more concise and maintainable structure.

Highlights

  • Improved Error Logging: Added console.error calls to all catch blocks in data.controller.js and schema.controller.js to ensure errors are explicitly logged for better debugging and visibility.
  • Code Cleanup and Readability: Removed several outdated or unnecessary comments across both data.controller.js and schema.controller.js, enhancing code clarity and maintainability.
  • Comment Refinement: Adjusted a comment regarding schema validation in data.controller.js for improved accuracy.
Changelog
  • backend/controllers/data.controller.js
    • Added console.error(err) to the catch blocks of insertData, getAllData, getSingleDoc, updateSingleData, and deleteSingleDoc functions.
    • Removed the comment "// Prevnt NoSQL injection".
    • Changed the comment "// Strict Schema Validation" to "// Schma Validation".
    • Removed the comment "// Unknown fields ko ignore karo".
  • backend/controllers/schema.controller.js
    • Added console.error(err) to the catch blocks of checkSchema and createSchema functions.
    • Removed comments related to fetching the full project document and transforming API payload fields.
    • Removed the comment "// In case it was cached by hashed key" and "// NOTE: req.hashedApiKey is available from middleware if we strictly want that.".
Activity
  • No specific activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@yash-pouranik
yash-pouranik temporarily deployed to feat/ui-updates - urBackend-frankfrut PR #30 March 2, 2026 16:55 — with Render Destroyed
@coderabbitai

coderabbitai Bot commented Mar 2, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Enhanced error logging and code quality in backend controllers. Added console.error() calls in catch blocks across data and schema controllers, introduced a null-check guard for project retrieval, and removed stray comments. No changes to function signatures or core validation logic.

Changes

Cohort / File(s) Summary
Error Logging Enhancements
backend/controllers/data.controller.js, backend/controllers/schema.controller.js
Added console.error(err) statements to catch blocks in insertData, getAllData, getSingleDoc, updateSingleData, deleteSingleDoc, checkSchema, and createSchema to improve error visibility during runtime.
Data Controller Cleanup
backend/controllers/data.controller.js
Removed stray NoSQL injection comment, adjusted "Strict Schema Validation" comment (typo), and removed inline comment about unknown fields handling; validation logic remains unchanged.
Schema Controller Guard
backend/controllers/schema.controller.js
Added null-check guard in createSchema: returns 404 "Project not found" if fullProject is falsy. Minor comment removals with no impact to Redis cache invalidation or error handling logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Errors now logged, their tales are told,
No more mysteries, no more untold,
A guard keeps projects safe and sound,
Comments cleaned, yet logic's found!
Better code hops through the night,
With error visibility burning bright! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The PR title contains a typo ('errro' instead of 'error') and is vague; it doesn't clearly convey the actual changes including error logging, guard clause additions, and minor comment adjustments across multiple controller files. Correct the typo and use a more descriptive title such as 'chore: add error logging and validation improvements to controllers' to better reflect the changeset.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/ui-updates

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces console.error logging within catch blocks across several controllers, enhancing error visibility. However, a security audit identified significant NoSQL injection vulnerabilities in the data handling logic. Specifically, the getAllData function lacks sanitization for query parameters, and the updateSingleData function has incomplete validation for 'Date' fields, potentially allowing attackers to manipulate database queries. Implementing robust input validation and sanitization, ideally with a dedicated library for MongoDB operator stripping, is strongly recommended to mitigate these risks. Additionally, for improved logging practices, consider adopting a structured logger for all new console.error calls. Please also address a minor typo in a comment and a small typo in the pull request title.

console.timeEnd("getall")
res.json(data);
} catch (err) {
console.error(err);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

The getAllData function is vulnerable to NoSQL injection because it passes the unsanitized req.query object to the QueryEngine. The QueryEngine.filter method directly assigns query parameters to the MongoDB query object, allowing an attacker to use MongoDB operators (e.g., ?field[$ne]=value) to bypass filters or extract sensitive data. Although this line adds error logging, the underlying function remains insecure.

for (const key in incomingData) {
const fieldRule = schemaRules.find(f => f.key === key);
if (!fieldRule) continue; // Unknown fields ko ignore karo
if (!fieldRule) continue;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

The updateSingleData function is vulnerable to NoSQL injection, particularly for fields defined as 'Date' in the schema. The validation loop modified here lacks a type check for 'Date' fields, allowing an attacker to provide an object containing MongoDB operators (e.g., {"myDateField": {"$gt": ""}}). Since the sanitize function only checks top-level keys for the $ prefix, these nested operators will bypass sanitization and be passed directly to Model.findByIdAndUpdate, potentially leading to unauthorized data manipulation.

console.timeEnd("insert data")
res.status(201).json(result);
} catch (err) {
console.error(err);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While console.error is useful, for production environments it's recommended to use a structured logger (e.g., Winston, Pino). Structured logging provides more context with log levels, can output in machine-readable formats like JSON for easier analysis with log management tools, and offers more flexible configuration.

const Model = getCompiledModel(connection, collectionConfig, project._id, project.resources.db.isExternal);

// Strict Schema Validation
// Schma Validation

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There's a typo in this comment. It should be 'Schema'.

Suggested change
// Schma Validation
// Schema Validation

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
backend/controllers/schema.controller.js (1)

30-30: Use const for non-reassigned project.

Line 30 does not reassign project, so const communicates intent better.

Proposed small cleanup
-        let project = req.project;
+        const project = req.project;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/controllers/schema.controller.js` at line 30, Change the variable
declaration from mutable to immutable: replace the "let project = req.project"
binding in schema.controller.js with a const declaration (i.e., use "const
project") since the variable is not reassigned; update any surrounding comments
or usages if needed but keep the identifier "project" unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@backend/controllers/data.controller.js`:
- Line 140: Replace the typo in the inline comment reading "Schma Validation"
with the correct "Schema Validation" so the validation section comment is clear
and accurate (search for the exact comment string "Schma Validation" in
backend/controllers/data.controller.js and update it to "Schema Validation").

In `@backend/controllers/schema.controller.js`:
- Line 57: Add a null-safety guard before calling deleteProjectByApiKeyCache:
check that fullProject && fullProject.apiKey is truthy and only then call
deleteProjectByApiKeyCache(fullProject.apiKey). Mirror the existing pattern used
for req.hashedApiKey (lines handling req.hashedApiKey) so you avoid constructing
malformed cache keys when fullProject.apiKey is falsy.

---

Nitpick comments:
In `@backend/controllers/schema.controller.js`:
- Line 30: Change the variable declaration from mutable to immutable: replace
the "let project = req.project" binding in schema.controller.js with a const
declaration (i.e., use "const project") since the variable is not reassigned;
update any surrounding comments or usages if needed but keep the identifier
"project" unchanged.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 75c419a and d45c393.

📒 Files selected for processing (2)
  • backend/controllers/data.controller.js
  • backend/controllers/schema.controller.js

const Model = getCompiledModel(connection, collectionConfig, project._id, project.resources.db.isExternal);

// Strict Schema Validation
// Schma Validation

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix typo in validation comment.

Line 140 says Schma Validation; please rename it to Schema Validation for clarity.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/controllers/data.controller.js` at line 140, Replace the typo in the
inline comment reading "Schma Validation" with the correct "Schema Validation"
so the validation section comment is clear and accurate (search for the exact
comment string "Schma Validation" in backend/controllers/data.controller.js and
update it to "Schema Validation").

await setProjectById(projectId.toString(), fullProject);
await deleteProjectByApiKeyCache(fullProject.apiKey); // In case it was cached by hashed key
// NOTE: req.hashedApiKey is available from middleware if we strictly want that.
await deleteProjectByApiKeyCache(fullProject.apiKey);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Check Project model for apiKey requirement/default =="
fd 'Project\.(js|ts)$' | while read -r f; do
  echo "--- $f ---"
  rg -n -C3 'apiKey|required|default' "$f" || true
done

echo
echo "== Inspect deleteProjectByApiKeyCache null/falsy handling =="
fd 'redisCaching\.(js|ts)$' | while read -r f; do
  echo "--- $f ---"
  rg -n -C4 'deleteProjectByApiKeyCache|apiKey|toString\(' "$f" || true
done

Repository: yash-pouranik/urBackend

Length of output: 2373


🏁 Script executed:

# Find schema.controller.js and read context around line 57
fd 'schema\.controller\.js$' | head -1 | xargs cat -n | sed -n '40,75p'

Repository: yash-pouranik/urBackend

Length of output: 1535


Add a guard before invalidating API-key cache.

Line 57 passes fullProject.apiKey directly to deleteProjectByApiKeyCache, which lacks null-safety and would create a malformed cache key (e.g., project:apikey:null) if the value is ever falsy. Though the schema requires apiKey, defensive guarding aligns with the pattern already used at lines 58–60 for req.hashedApiKey.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/controllers/schema.controller.js` at line 57, Add a null-safety guard
before calling deleteProjectByApiKeyCache: check that fullProject &&
fullProject.apiKey is truthy and only then call
deleteProjectByApiKeyCache(fullProject.apiKey). Mirror the existing pattern used
for req.hashedApiKey (lines handling req.hashedApiKey) so you avoid constructing
malformed cache keys when fullProject.apiKey is falsy.

@yash-pouranik
yash-pouranik merged commit ec58b3f into main Mar 2, 2026
7 checks passed
@yash-pouranik
yash-pouranik deleted the feat/ui-updates branch March 4, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant